<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="${projectDefinitionDO.serverProjectDefinitionDO.serverProjectStartClassPackagePathName}.dao.AccountInfoDAO">

    <resultMap id="AccountInfoDO" type = "${projectDefinitionDO.serverProjectDefinitionDO.serverProjectStartClassPackagePathName}.domain.AccountInfoDO">
        <id column="account_info_id" property="accountInfoId" />
        <result column="user_name"  property="userName"  />
        <result column="mail"  property="mail"  />
        <result column="account_num"  property="accountNum"  />
        <result column="description"  property="description"  />
        <result column="create_time"  property="createTime"  />
        <result column="update_time"  property="updateTime"  />
        <result column="is_delete"  property="isDelete"  />
    </resultMap>

    <sql id="all_columns">
        <![CDATA[  account_info_id ,  user_name ,  mail ,  account_num ,  description ,  create_time ,  update_time , is_delete ]]>
    </sql>

    <sql id="select_columns">
        <choose>
            <when test="specifiedColumns !=null "> ${r'${specifiedColumns}'} </when>
            <otherwise> <include refid="all_columns" /> </otherwise>
        </choose>
    </sql>


    <sql id="query_condition">
        <#noparse>
            <if test = "accountInfoId != null " ><![CDATA[ AND account_info_id = #{accountInfoId}]]></if>
            <if test = "accountInfoIdSet != null and accountInfoIdSet.size()!=0" >
                AND account_info_id IN
                <foreach item="item" index="index" collection="accountInfoIdSet" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test = "userName != null " ><![CDATA[ AND user_name = #{userName}]]></if>
            <if test = "userNameSet != null and userNameSet.size()!=0" >
                AND user_name IN
                <foreach item="item" index="index" collection="userNameSet" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test = "mail != null " ><![CDATA[ AND mail = #{mail}]]></if>
            <if test = "accountNum != null " ><![CDATA[ AND account_num = #{accountNum}]]></if>
            <if test = "accountNumSet != null and accountNumSet.size()!=0" >
                AND account_num IN
                <foreach item="item" index="index" collection="accountNumSet" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test = "fuzzyDescription != null " ><![CDATA[ AND description LIKE concat(concat('%',#{fuzzyDescription}),'%')]]></if>
            <if test = "lessThanCreateTime != null " ><![CDATA[ AND create_time < #{lessThanCreateTime}]]></if>
            <if test = "equalAndLessThanCreateTime != null " ><![CDATA[ AND create_time <= #{equalAndLessThanCreateTime}]]></if>
            <if test = "moreThanCreateTime != null " ><![CDATA[ AND create_time > #{moreThanCreateTime}]]></if>
            <if test = "equalAndMoreThanCreateTime != null " ><![CDATA[ AND create_time >= #{equalAndMoreThanCreateTime}]]></if>
            <if test = "lessThanUpdateTime != null " ><![CDATA[ AND update_time < #{lessThanUpdateTime}]]></if>
            <if test = "equalAndLessThanUpdateTime != null " ><![CDATA[ AND update_time <= #{equalAndLessThanUpdateTime}]]></if>
            <if test = "moreThanUpdateTime != null " ><![CDATA[ AND update_time > #{moreThanUpdateTime}]]></if>
            <if test = "equalAndMoreThanUpdateTime != null " ><![CDATA[ AND update_time >= #{equalAndMoreThanUpdateTime}]]></if>
            <if test = "isDelete != null " ><![CDATA[ AND is_delete = #{isDelete}]]></if>
        </#noparse>
     </sql>

     <insert id="insertAccountInfo" parameterType="${projectDefinitionDO.serverProjectDefinitionDO.serverProjectStartClassPackagePathName}.domain.AccountInfoDO" useGeneratedKeys="true" keyProperty="accountInfoId">
         INSERT INTO account_info (<include refid="all_columns" />) VALUES
         (
         ${r' #{accountInfoId} , #{userName} , #{mail} , #{accountNum} , #{description} , #{createTime} , #{updateTime} , #{isDelete}'}
         )
     </insert>


     <select id="selectAccountInfoList" resultMap="AccountInfoDO" parameterType="${projectDefinitionDO.serverProjectDefinitionDO.serverProjectStartClassPackagePathName}.domain.query.QueryAccountInfo">
         SELECT <include refid="select_columns" /> FROM account_info
         <where>
             <include refid="query_condition"/>
         </where>
         ${r'<if test="orderByClause !=null" > ORDER BY ${orderByClause}</if>'}
         <!-- add order or query info. -->
        <![CDATA[

        ]]>

        ${r'<if test="startNum != null" > LIMIT #{startNum},#{pageSize}</if>'}
    </select>


    <select id="countAccountInfoList" resultType="int" parameterType="${projectDefinitionDO.serverProjectDefinitionDO.serverProjectStartClassPackagePathName}.domain.query.QueryAccountInfo">
        SELECT COUNT(1) FROM account_info
        <where>
            <include refid="query_condition"/>
        </where>

        <!-- add order or query info. -->
        <![CDATA[

        ]]>
    </select>

    <select id="selectDistinctList" resultType="String" parameterType="${projectDefinitionDO.serverProjectDefinitionDO.serverProjectStartClassPackagePathName}.domain.query.QueryAccountInfo">
        SELECT DISTINCT(${r' ${distinct} '}) FROM  account_info <where>  <include refid="query_condition"/> 	</where>
    </select>

    <select id="selectAccountInfoByAccountInfoId" resultMap="AccountInfoDO" parameterType="Long">
        SELECT <include refid="all_columns" /> FROM account_info WHERE account_info_id = ${r' #{accountInfoId}'}
    </select>

    <update id="updateAccountInfoByAccountInfoId" parameterType="${projectDefinitionDO.serverProjectDefinitionDO.serverProjectStartClassPackagePathName}.domain.AccountInfoDO">
        UPDATE account_info
        <set>
            ${r'<if test="userName!=null"><![CDATA[user_name=#{userName},]]></if>'}
            ${r'<if test="mail!=null"><![CDATA[mail=#{mail},]]></if>'}
            ${r'<if test="accountNum!=null"><![CDATA[account_num=#{accountNum},]]></if>'}
            ${r'<if test="description!=null"><![CDATA[description=#{description},]]></if>'}
            ${r'<if test="createTime!=null"><![CDATA[create_time=#{createTime},]]></if>'}
            ${r'<if test="updateTime!=null"><![CDATA[update_time=#{updateTime},]]></if>'}
            ${r'<if test="isDelete!=null"><![CDATA[is_delete=#{isDelete},]]></if>'}
        </set>

        <![CDATA[ WHERE  account_info_id = ${r' #{accountInfoId} '}]]>

    </update>

</mapper>
